package Model::Bots;

use strict;
use WA::Model2;
our @ISA=( 'WA::Model2' );
use utf8;
use Encode;

sub fields { ['pid', 'startTime', 'idStr'] }
sub tablename { 'bots' }

sub Alone {
	my $self=shift;

	$self->where(
		idStr => $self->get('idStr')
	)->load() and kill(0, $self->get('pid')) and exit;

	$self->set(
		idStr => $self->get('idStr'),
		pid => $$,
	)->set_raw(
		startTime => 'NOW()' 
	)->save() or exit;
}

sub kill_exists {
	my $self=shift;
	$self->where(
		idStr => $self->get('idStr')
	)->load() and kill(9, $self->get('pid'));
}

sub new {
	my($self, $identifer)=@_;
	die('no identifer') unless $identifer;
	$self->SUPER::new->set(
		idStr => $identifer
	);
}

1;
